package com.demo.study.algorithm.leetcode;

import org.junit.Test;

import static com.demo.study.utils.ArrayUtil.printArray;

/**
 * LT1480
 * <a href="https://leetcode.cn/problems/running-sum-of-1d-array/description">一维数组的动态和</a>
 *
 * @author Baymax
 * @since 2024-11-15
 */
public class LT1480 {
    @Test
    public void run() {
        printArray(runningSum(new int[]{1, 2, 3, 4}));
    }

    public int[] runningSum(int[] nums) {
        int[] result = new int[nums.length];
        result[0] = nums[0];
        for (int i = 1; i < nums.length; i++) {
            result[i] = nums[i] + result[i - 1];
        }
        return result;
    }

    // public int[] runningSum(int[] nums) {
    //     for(int i = 1; i < nums.length; i++) {
    //         nums[i] += nums[i -1];
    //     }
    //     return nums;
    // }
}
